package com.qcnh.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qcnh.entity.Payment;
import com.qcnh.entity.Reservation;
import com.qcnh.service.impl.ReservationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import unil.Result;

import java.util.List;

/**
 * <p>
 * 预约表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2024-12-05
 */
@RestController
@RequestMapping("reservation")//预约
public class ReservationController {
    @Autowired
    private ReservationServiceImpl reservationService;

    // 分页模糊查询所有预约
    @GetMapping("selectAllReservations")
    public Result selectAllReservations(@RequestParam(value = "current",defaultValue = "1") Integer current,
                            @RequestParam(value = "size",defaultValue = "10") Integer size,
                            @RequestParam(value = "keyWord",defaultValue = "false") String keyWord) {
        IPage<Reservation> Ipage = reservationService.selectAllReservations(current, size, keyWord);//使用mybatis自带的分页查询方法处理
        if(Ipage == null)//判空处理
            return Result.fail(400,"未查询到预约信息",null);
        return Result.ok(200,"预约信息遍历成功",Ipage);
    }

    //添加单个预约
    @PostMapping("addReservation")
    public Result addReservation(@RequestBody Reservation reservation) {
        if(reservationService.addReservation(reservation))//使用mybatis自带的添加方法处理
            return Result.ok(200,"添加预约成功",1);
        return Result.fail(400,"添加预约失败",null);
    }

    //根据id集合批量删除预约
    @DeleteMapping("delReservationsByIdList")
    public Result delReservationsByIdList(@RequestBody List<Integer> reservationIds){
        if(reservationService.delReservationsByIdList(reservationIds))
            return Result.ok(200,"删除预约成功",1);
        return Result.fail(400,"删除预约失败",null);
    }

    //根据id修改公告预约
    @PutMapping("updateReservation")
    public Result updateReservation(@RequestBody Reservation reservation){
       if(reservationService.updateReservation(reservation))
           return Result.ok(200,"更新预约成功",1);
        return Result.fail(400,"更新预约失败",null);
    }

}

